<template>
    <div>
      <Form ref="form" :model="form" :rules="rules">
        <FormItem leble="公告内容" prop="content">
          <Input v-model="form.content" style="width: 250px" placeholder="请输入公告内容"></Input>
        </FormItem>
        <FormItem leble="创建时间" prop="create_date">
          <DatePicker v-model="form.create_date" style="width: 250px" type="date" placeholder="请选择时间"></DatePicker>
        </FormItem>
        <FormItem>
          <Button type="primary" style="margin: 15px" @click="add">提交</Button>
          <Button type="text" @click="quxiao">取消</Button>
        </FormItem>
      </Form>
      {{user}}
    </div>
</template>

<script>
export default {
  name: "addNotice",
  data(){
    return{
      form:{
        content: null,
        create_date:null,
        author:null,
      },
      rules:{
        content:[{required:true,message:"请输入公告内容"}],
        create_date:[{required:true,message:"请选择发布时间"}],
      }
    }
  },
  methods:{
    add(){

      this.$refs['form'].validate(valid=>{
        if (valid){
          this.form.create_date=(new Date(this.form.create_date)).toLocaleDateString()
          this.http.post("/setNotice",this.qs.parse(this.form)).then(res=>{
            if (res.data){
              this.$Message.success("添加成功")
              this.$emit("hideenDialog")
              this.$emit("after")
            }
          })
        }
      })
    },
    quxiao(){
      this.$emit("hideenDialog")
    }
  },
  computed:{
    user(){
       this.form.author=this.$store.state.user.name
    }
  }
}
</script>

<style scoped>

</style>
